package com.example.demo.service;

import com.example.demo.dao.order;
import com.example.demo.dao.orderRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;


@Service
public class orderServiceImpl implements orderService {

    @Autowired
    private orderRepository orderRepository;

    @Override
    public order addOrder(order order) {
        order orderdb = orderRepository.save(order);
        orderdb.setOrderformState("uns");
        orderRepository.save(orderdb);
        return orderdb;
    }

    @Override
    public List<order> getOrderByBuyName(String buyName) {
        List<order> orderdb = orderRepository.findByBuyName(buyName);
        return orderdb;
    }

    @Override
    public List<order> getOrderByBusinessName(String businessName) {
        List<order> orderdb = orderRepository.findByBusinessName(businessName);
        return orderdb;
    }

    @Override
    public order getOrderById(long orderformId) {
        order orderdb = orderRepository.findByOrderformId(orderformId);
        return orderdb;
    }

    @Override
    public order updOrderState(long orderformId,String orderformState) {
        order orderdb = orderRepository.findByOrderformId(orderformId);
        orderdb.setOrderformState(orderformState);
        orderRepository.save(orderdb);
        return orderdb;
    }

    @Override
    public void delOrderById(long orderformId) {
        orderRepository.deleteByorderformId(orderformId);
    }
}
